<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>订单详情</title>
    <link rel="stylesheet"  href="src/css/base.css?__version=9.4">
    <link rel="stylesheet"  href="src/css/pages.css?__version=9.4">
    <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8ed2efe5b24e14f351f4d88ba2eb3462";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
</head>
<body>
    <div class="warp orderDetails-warp">
    	<a href='siteList.html' >
        	<div class="choice-address" >
	            <img class="icon-address" src="src/img/shouhuodizhi.png">
	            <div class="nameTel" id="address">
	            	<div style="padding:15px 0;">点击添加收货地址</div>
	            </div>
	            <img class="icon-right" src="src/img/rightrow.png">
	            <i class="clearfix"></i>
	        </div>
        </a>
        <section class="caption" id="htmlDataList"></section>
        <div class="distribution">
        	<div class="distributionpay clearfix">配送方式 <img class="icon-right pull-right" src="src/img/rightrow.png"><span class="pull-right">包邮</span></div>
        	<!-- <div class="notes">注：一件邮费自付，两件及以上包邮</div> -->
        </div>
        <button type="button" class="btn btn-yellow" id="button" onclick='sub()' style="color:#666"></button>
    </div>
    
<script type="text/javascript" src="src/js/jquery-1.10.1.min.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/rem.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/dropload.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/init.js?__version=9.4"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/src/js/share.js?__version=9.4"></script>
</body>
<script>
addheader("订单详情","/backpack.html");
$(function (){
	
	//获取信息
	var toys = cookieGet('toys');
	toys = JSON.parse( toys );
	var htmlDataList = "";
	var numAll = 0;
	
	for(var i = 0;i<toys.length;i++){
		numAll = Number(numAll)+Number(toys[i].num);
		htmlDataList += '<label class="item flex">';
		htmlDataList += '<img src="'+toys[i].img+'" width="50px;" heoght="50px;">';
		htmlDataList += '<div class="info">';
		htmlDataList += '<p class="name text-beyond">'+toys[i].name+'</p>';
		htmlDataList += '<p class="num text-beyond">x'+toys[i].num+'</p>';
		htmlDataList += '</div>';
		htmlDataList += '</label>';
	}

	// if(numAll<2){
	// 	fetchData("/OpenAPI/v1/app/config",{},function(data){
	// 		$(".distribution .distributionpay span").html("运费"+data.postage+"金币");
	// 	})	
	// }else{
	// 	$(".distribution .distributionpay span").html("包邮");
	// }
	$("#button").append('确认订单');
	$("#htmlDataList").append(htmlDataList);
	
	
	//获取地址
	var address = cookieGet('confirmAddress');
	console.log(cookieGet('confirmAddress'))
	if(address.length == 0){
		$("#address > div").html("点击添加收货地址");
	}else{
		address = JSON.parse(address);
		var addressData = "";
		addressData += '<div class="inline-block text-beyond name" style="padding-top:8px">';
		addressData += '<span>收货人：</span>';
		addressData += '<span>'+address[0].name+'</span>';
		addressData += '</div>';
		addressData += '<div class="inline-block text-beyond tel" style="padding-top:8px">';
		addressData += '<span>联系方式：</span>';
		addressData += '<span>'+address[0].phone+'</span>';
		addressData += '</div>';
		addressData += '<div class="site text-beyond" style="padding-bottom:8px;">收货地址：'+address[0].region+' '+address[0].address+'</div>';
		$("#address").html(addressData);
	}
	
})
</script>

<script>
function sub(){
	var back_ids = cookieGet('back_ids');
	var address = cookieGet('confirmAddress');
	
	back_ids = JSON.parse(back_ids);
	if(address){
		address = JSON.parse(address);
		ress_id = address[0].address_id;
		$.ajax({
			type:'post',
			url:api_url+'/OpenAPI/V1/User/orderPost',
			data:{token:token,ress_id:ress_id,toy_ids:back_ids},
			jsonp:'callback',
			dataType:'jsonp',
			
			success:function (data){
				console.log(data);
				if(data.code == 0){
					alert('提交成功');
					window.location.href="/personal.html";
				}else{
					alert('提交失败');
					return;
				}
			},
		
			error:function (){
				alert('网络错误');
				return;
			}
		});
	}else{
		alert("地址不能为空")
	}
}
</script>
</html>